package labuladong.leetcode.editor.cn._00utils;

import labuladong.leetcode.editor.cn._00bean.ListNode;

/**
 * @author weibin
 * @create 2022-11-28 19:50
 */


public class LinkedListUtils {
    // 创建链表
    public static ListNode build(int[] nums) {
        ListNode dummy = new ListNode(-1), p = dummy;

        for (int num : nums) {
            p.next = new ListNode(num);
            p = p.next;
        }
        return dummy.next;
    }

    // 打印链表
    public static void print(ListNode node) {
        while (node != null) {
            if (node.next == null) {  //链表最后一个节点
                System.out.print(node.val);
                break;
            }
            System.out.print(node.val + "->");
            node = node.next;
        }
        System.out.println();
    }

}
